package com.link.base.base.invloc.service;

import com.link.base.base.invloc.dao.mybatis.mapper.InvProdMapper;
import com.link.base.base.invloc.model.InvProd;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: unknown
 * created: unknown
 * comments:
 */
@Service
@Transactional(rollbackFor = BasicServiceException.class)
public class InvProdServiceImpl extends BasicServiceImpl<InvProd> implements InvProdService {
    /**
     * 分页查询类型: 无批次查询，当QPS的attr1为WithoutBatch时，调用重写后的DAO层接口
     */
    private static final String QUERY_TYPE = "WithoutBatch";

    @Resource
    private InvProdMapper invProdMapper;

    @Override
    public BasicMapper<InvProd> getBasicMapper() {
        return invProdMapper;
    }

    /**按照id查询产品库存*/
    @Override
    public ArrayList<InvProd> queryInvProdByInvId(InvProd record) throws Exception {
        return invProdMapper.queryInvProdByInvId(record);
    }

    @Override
    public List<InvProd> queryByExamplePage(InvProd entity) throws Exception {
        if (QUERY_TYPE.equals(entity.getAttr1())) {
            return invProdMapper.queryByExampleWithoutBatchPage(entity);
        } else {
            return super.queryByExamplePage(entity);
        }
    }
}
